<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
		<%
		//第一步: 获取参数
		request.setCharacterEncoding("utf-8");
		String sno = request.getParameter("sno");
		String sdep = request.getParameter("sdep");
		String ssex = request.getParameter("ssex");
		String sage = request.getParameter("sage");
		String sname = request.getParameter("sname");
		
		//第二步: 连接数据库
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/st?useUnicode=true&characterEncoding=utf-8";
			String user = "root";
			String pass = "123456";
			Connection con = DriverManager.getConnection(url,user,pass);
			
		//第三步: 调用prepareStatement方法,对数据库进行增加数据的操作
		PreparedStatement ps = con.prepareStatement("update student2 set sdep=?,ssex=?,sage=?,sname=? where sno=?");
		ps.setString(1, sdep);
		ps.setString(2, ssex);
		ps.setInt(3, Integer.parseInt(sage));
		ps.setString(4, sname);
		ps.setString(5, sno);
		
		//将数据更新
		ps.executeUpdate();
		
		//第四步: 关闭数据库
		ps.close();
		con.close();
		
		//第五步: 增加数据执行完成后,跳转回showinfo1.jsp界面
		request.getRequestDispatcher("showinfo1.jsp").forward(request, response);
		
		//第六步: 避免出现异常
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		%>
</body>
</html>